package com.hu.zhcc.shiro.controller;

import com.hu.zhcc.shiro.entity.tj.Dept;
import com.hu.zhcc.shiro.entity.tj.Emp;
import com.hu.zhcc.shiro.service.DeptService;
import com.hu.zhcc.shiro.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/emp")
public class EmpsController {
    @Autowired
    private EmpService empService;
    @Autowired
    private DeptService deptService;
    //查询所有
    @GetMapping("EmpQueryAll")
    public List<Emp> queryAllEmp(){
        return empService.queryAll();
    }
    //模糊查询
    @GetMapping("")
    public List<Emp> listEmp(Emp emp){
        return empService.listEmp(emp);
    }
    //根据编号删除
    @DeleteMapping("/{id}")
    public int delEmp(@PathVariable("id") Integer id){
        int i = empService.deleteByPrimaryKey(id);
        return i;
    }
    //根据编号进行查询
    @GetMapping("/{id}")
    public Emp queryById(@PathVariable("id") Integer id){
      return  empService.selectByPrimaryKey(id);
    }
    //修改
    @PutMapping("")
    public int updEmp(@RequestBody Emp emp){
        System.out.println(emp);
        int i = empService.updateByPrimaryKey(emp);
        return i;
    }
    //添加
    @PostMapping("")
    public int addEmp(@RequestBody Emp emp){
        int insert = empService.insert(emp);
        System.out.println(emp);
        return insert;
    }
    //查询部门
    @GetMapping("queryAllDept")
    public List<Dept> queryAllDept(){
       return deptService.queryAll();
    }

}
